package thread;

import socket.Server;

import java.io.FileNotFoundException;

/**
 * 静态方法上使用synchronized,那么该方法一定具有同步的效果*/
public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1 = new Foo();
        Foo f2 = new Foo();
        Thread t1 = new Thread(()->f1.doSome());
        Thread t2 = new Thread(()-> f2.doSome());
        t1.start();
        t2.start();
    }
}
class Foo{
    public static void doSome(){
        /*不使用字面量R:*/
        synchronized (Foo.class){
            Thread thread = Thread.currentThread();
            System.out.println(thread.getName()+"正在执行....");

            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(thread.getName()+"执行完成....");
        }

    }
}
